home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / arc42s.lbr / ARCTST.MQC / arctst.mac
Text File  |  1985-08-04  |  3KB  |  67 lines

  1. /*  ARC - Archive utility - ARCTST
  2.  
  3. $define(tag,$$segment(@1,$$index(@1,=)+1))#
  4. $define(version,Version $tag(
  5. TED_VERSION DB =2.07), created on $tag(
  6. TED_DATE DB =06/25/85) at $tag(
  7. TED_TIME DB =10:12:15))#
  8. $undefine(tag)#
  9.     $version
  10.  
  11. (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  12.  
  13.     By:  Thom Henderson
  14.  
  15.     Description:
  16.          This file contains the routines used to test archive integrity.
  17.  
  18.     Language:
  19.          Computer Innovations Optimizing C86
  20. */
  21. #include <stdio.h>
  22. #include "arc.h"
  23.  
  24. tstarc()                               /* test integrity of an archive */
  25. {
  26.     int errs = 0;                      /* number of problems */
  27.     struct heads hdr;                  /* file header */
  28.     long arcsize, ftell();             /* archive size */
  29.  
  30.     openarc(0);                        /* open archive for reading */
  31.     fseek(arc,0L,2);                   /* move to end of archive */
  32.     arcsize = ftell(arc);              /* see how big it is */
  33.     fseek(arc,0L,0);                   /* return to top of archive */
  34.  
  35.     while(errs<21 && !feof(arc))
  36.     {    if(fgetc(arc)!=$arcmark)      /* check for the mark of ARC */
  37.          {    printf("%s is not an archive or is out of sync\n",arcname);
  38.               errs++;
  39.          }
  40.          else                          /* we can process it */
  41.          {    hdrver = fgetc(arc);     /* get header version */
  42.               if(hdrver==0)            /* special kludge for end marker */
  43.                    break;
  44.               else if(hdrver==1)       /* special kludge for old headers */
  45.                    fread(&hdr,sizeof(hdr)-sizeof(long),1,arc);
  46.               else fread(&hdr,sizeof(hdr),1,arc);
  47.  
  48.               if(ftell(arc)+hdr.size>arcsize)
  49.               {    printf("Archive truncated in file %s\n",hdr.name);
  50.                    errs++;
  51.                    break;
  52.               }
  53.  
  54.               else if(unpack(arc,NULL,&hdr))
  55.                    errs++;
  56.  
  57.               else printf("File %s is okay\n",hdr.name);
  58.          }
  59.     }
  60.  
  61.     if(errs>20)
  62.          printf("More than twenty errors detected\n");
  63.     else if(errs)
  64.          printf("%d errors detected\n",errs);
  65.     else printf("No errors detected\n");
  66. }
  67.